﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HRS_Service
{
    public class Utilities
    {
        public static DataAccessLayer.Guest convert(HRS_Service.BookingWCF.Guest g)
        {
            DataAccessLayer.Guest guest = new DataAccessLayer.Guest();
            guest.FirstName = g.firstName;
            guest.LastName = g.lastName;
            guest.Phone = g.phone;
            guest.Address = g.address;
            guest.City = g.city;
            guest.Country = g.country;
            guest.CreditNumber = g.creditNo;
            guest.CVVNumber = g.cvv;
            guest.Email = g.email;
            guest.ExpirationDate = g.creditExpiryDate;
            guest.State = g.state;
            return guest;
        }

        public static DataAccessLayer.Booking convert(HRS_Service.BookingWCF.Booking b)
        {
            DataAccessLayer.Booking booking = new DataAccessLayer.Booking();
            booking.StartDate = b.startDate;
            booking.EndDate = b.endDate;
            booking.RoomTypeID = b.roomTypeID;
            booking.BookingNumber = b.bookingNumber;
            return booking;
        }

        public static DataAccessLayer.RoomType convert(HRS_Service.BookingWCF.RoomType rt)
        {
            DataAccessLayer.RoomType roomType = new DataAccessLayer.RoomType();
            roomType.Description = rt.description;
            roomType.RoomTypeName = rt.RoomTypeName;
            roomType.Price = rt.price;
            roomType.ID = Convert.ToInt32(rt.id);
            roomType.NumberOfBed = rt.NoOfBed;
            roomType.NumberOfRoom = rt.NoOfBed;
            return roomType;
        }

        public static HRS_Service.BookingWCF.RoomType convert(DataAccessLayer.RoomType rt)
        {
            HRS_Service.BookingWCF.RoomType roomType = new BookingWCF.RoomType();
            roomType.description = rt.Description;
            roomType.id = Convert.ToString(rt.ID);
            roomType.NoOfBed = rt.NumberOfBed.Value;
            roomType.RoomTypeName = rt.RoomTypeName;
            roomType.price = rt.Price.Value;
            roomType.NoOfRoom = rt.Price.Value; return roomType;
        }




        internal static BookingWCF.Booking convert(DataAccessLayer.Booking b)
        {
            HRS_Service.BookingWCF.Booking b1 = new BookingWCF.Booking();
            b1.endDate = b.EndDate.Value;
            b1.startDate = b.StartDate.Value;
            b1.roomTypeID = b.RoomTypeID.Value;
            b1.bookingNumber = b.BookingNumber;
            
            return b1;
        }

        public static BookingWCF.Guest convert(DataAccessLayer.Guest g)
        {
            HRS_Service.BookingWCF.Guest g1 = new BookingWCF.Guest();
            g1.id = g.ID;
            g1.firstName = g.FirstName;
            g1.lastName = g.LastName;
            g1.postal = g.ZipPostalCode;
            g1.phone = g.Phone;
            g1.state = g.State;
            return g1;


        }

        public static List<HRS_Service.BookingWCF.Booking> convert(IEnumerable<DataAccessLayer.Booking> bookings)
        {
            List<HRS_Service.BookingWCF.Booking> bookings1 = new List<BookingWCF.Booking>();
            foreach (DataAccessLayer.Booking b in bookings)
            {
                HRS_Service.BookingWCF.Booking b1 = convert(b);
                bookings1.Add(b1);
            } 
            return bookings1;
        }
    }
}